package com.cebbank.yyi.impl;

import com.cebbank.yyi.properties.ConnectionProperties;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

/**
 * @description:
 * @author: yyi
 * @date: 2022/8/25 10:50
 * @version: 1.0
 **/

public class Impl {

    @Autowired
    private ConnectionProperties connectionProperties;

    @SneakyThrows
    public PreparedStatement getSate(String sql, Object... args) {
        Class.forName(connectionProperties.getDriver());
        Connection connection = DriverManager.getConnection(connectionProperties.getUrl(), connectionProperties.getUserName(), connectionProperties.getPassword());
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        for (int i = 0; i < args.length; i++) {
            preparedStatement.setString(i + 1, (String) args[i]);
        }
        return preparedStatement;
    }
    //关闭连接

}
